################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis ESS
#Figure B 7
#
#Verena Fetscher
#July 2022
####################

####################
# Load data
####################
source("dataframes.R")


##########################
#Benefit concentration indicators versus alternative measures: Benefit concentration and top statutory personal income tax rate
##########################

cor.test(data_sub$social_spending,data_sub$benefitsAvgYear, method=c("pearson"))

##########################
# Produces Figure B.7: Benefit concentration and top statutory personal income tax rate, averaged over 2002-2014.
##########################

data_sub%>%
  group_by(country)%>%
  summarize(benefits=mean(benefitsAvg),
            toptax=mean(toptax))%>%
  ggplot(aes(x=benefits, y=toptax)) +
  geom_point() + 
  #ggtitle("Benefit concentration and top income tax") + 
  geom_smooth(method=lm, se=T) + 
  scale_x_continuous(name = "Benefit concentration", limits = c(0, 1)) + 
  scale_y_continuous(name = "Top income tax") + 
  theme_bw()


##########################
#Save figure
##########################

ggsave(file="figure_b7.pdf", height = 5.83, width = 8.27, units = "in")

